﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaxiService.Model
{
  public static class DomainEvents
  {
    [ThreadStatic]
    private static List<Delegate> _actions = new List<Delegate>();

    public static void Register<T>(Action<T> callback) where T : IDomainEvent
    {
      _actions.Add(callback);
    }

    public static void ClearCallbacks()
    {
      _actions.Clear();
    }

    public static void Raise<T>(T args) where T : IDomainEvent
    {
      _actions.Where(x => x is Action<T>)
        .ToList().ForEach(x => ((Action<T>)x)(args));
    }
  }
}
